package gepes.servlet;

import gepes.modelo.CategoriaProfesor;
import gepes.modelo.Profesor;
import gepes.modelo.SubCategoria;
import gepes.negocio.GestionProfesor;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ProfesorCategoriaElimina
 */
@WebServlet("/ProfesorCategoriaElimina")
public class ProfesorCategoriaElimina extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProfesorCategoriaElimina() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int idprof = Integer.parseInt(request.getParameter("idProf"));
		int idcat = Integer.parseInt(request.getParameter("idC"));

		GestionProfesor negocio = new GestionProfesor();
		try {
			CategoriaProfesor pr = new CategoriaProfesor();
			pr.setProfesor(new Profesor(idprof));
			pr.setSubCategoria(new SubCategoria(idcat));
			negocio.eliminaCategoriaProfesor(pr);
			HttpSession sessionMi = request.getSession();
			sessionMi.setAttribute("msg", "Registro eliminado");
			sessionMi.setAttribute("pagina", "Historia1-3.jsp");
			
			RequestDispatcher rd = request
					.getRequestDispatcher("mensaje.jsp");
			rd.forward(request, response);
		} catch (gepes.exepcion.DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
